define(function(require) {
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");

	var Model = function() {
		this.callParent();
		this.url = "http://yun.jiawoltd.com";
	};

	Model.prototype.loginBtnClick = function(event) {
		var userName = this.comp("nameInput").val();
		var password = this.comp("passwordInput").val();
		$.ajax({
			cache : false,
			type : "POST",
			timeout : 10000, // 超时时间设置，单位毫秒
			url : this.url + "/mobile/login/",
			data : {
				userName : userName,
				password : password
			},
			async : false,
			error : function(request) {
				justep.Util.hint("网络错误,请稍后再试!");
			},
			success : function(resp) {
				if (resp && resp.code == '0') {
					localStorage.setItem("USER_NAME", userName);
					localStorage.setItem("USER_ID", resp.userId);
					justep.Shell.setIsSinglePage();
					justep.Shell.showPage(require.toUrl('./main.w'), {});
					
				} else {
					justep.Util.hint("用户名或密码错误!");
				}
			}
		});
	};
	Model.prototype.modelLoad = function(event) {
		var userId = localStorage.getItem("USER_ID");
		if (userId) {
			//justep.Shell.setIsSinglePage();
			//justep.Shell.showPage(require.toUrl('./main.w'), {});
			justep.Shell.closePage();
		}
	};
	return Model;
});